﻿@model WebEditor.Models.StringDictionary

@if (Model.Value != null && Html.ViewData.ModelState.ContainsKey(Model.Value.Id) && Html.ViewData.ModelState[Model.Value.Id].Errors.Count > 0)
{
    <div class="elementEditorError">
        @Html.ValidationMessage(Model.Value.Id)
        <button type="button" class="error-clear" data-key="@Model.Value.Id">Clear</button>
    </div>
}

<div class="stringDictionarySection ui-widget-header ui-corner-all toolbar" id="stringDictionarySection-toolbar-@Model.Attribute" style="display: none">
    <button type="button" class="stringDictionarySection-delete" data-key="@Model.Attribute">Remove</button>
</div>

@if (Model.Value != null)
{
    <div class="stringDictionarySection">
        <table>
            <thead>
                <tr>
                    <th></th>
                    @if (!Model.GameBook)
                    {
                        <th>Key</th>
                        <th>Value</th>
                    }
                    else
                    {
                        <th>Page</th>
                        <th>Link text</th>
                    }
                </tr>
            </thead>
            <tbody>
                @{
                    int itemCount = 0;
                    foreach (var item in Model.Value.Items.Values)
                    {
                        <tr>
                            <td>@Html.CheckBox("selectstringitem-" + Model.Attribute + "-" + itemCount.ToString(), new { @class = "stringDictionarySection-select", data_key = Model.Attribute })</td>
                            @if (string.IsNullOrEmpty(Model.Source))
                            {
                                <td>@Html.TextBox(Model.Attribute + "-key" + itemCount.ToString(), item.Key)</td>
                            }
                            else
                            {
                                <td><a class="elementLink">@item.Key</a></td>
                            }
                            <td>@Html.TextBox(Model.Attribute + "-value" + itemCount.ToString(), item.Value, new { @class = "stringDictionaryValue" })</td>
                        </tr>
                            itemCount++;
                    }
                }
            </tbody>
        </table>
    </div>
}

<div class="stringDictionarySection">
    @if (Model.GameBook)
    {
        <button type="button" class="gamebookoptions-addnew" data-key="@Model.Attribute" data-prompt="@Model.KeyPrompt">Add New Page</button>
    }
    @{
        string buttonClass = Model.GameBook ? "gamebookoptions-link" : "string-dictionary-add";
        string buttonText = Model.GameBook ? "Add Link to Existing Page" : "Add";
    }
    <button type="button" class="@buttonClass" data-key="@Model.Attribute" data-prompt="@Model.KeyPrompt" data-source="@Model.Source" data-source-exclude="@Model.SourceExclude">@buttonText</button>
</div>